package com.zmn.oms.zmn.business.impl.work.financework;

import com.alibaba.fastjson.JSON;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.pay.PayResultDTO;
import com.zmn.common.utils.date.DateUtil;
import com.zmn.oms.business.impl.work.financework.FinanceWorkBServiceImpl;
import com.zmn.oms.common.dto.OmsPayRequestDTO;
import com.zmn.oms.model.entity.work.OrderWork;
import com.zmn.oms.services.interfaces.work.OrderWorkService;
import com.zmn.oms.services.interfaces.work.financework.FinanceWorkService;
import com.zmn.oms.zmn.business.interfaces.warranty.ZsOrderWarrantyBService;
import com.zmn.oms.zmn.business.interfaces.work.financework.ZsFinanceWorkBService;
import com.zmn.pay.common.constant.PayConsts;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 类描述：财务工单业务实现
 *
 * @author lujia
 * @date 2018/11/02 21:02
 */
@Service
public class ZsFinanceWorkBServiceImpl extends FinanceWorkBServiceImpl implements ZsFinanceWorkBService {

    @Autowired
    private OrderWorkService orderWorkService;
    @Autowired
    private FinanceWorkService financeWorkService;
    @Autowired
    private ZsOrderWarrantyBService zsOrderWarrantyBService;

    @Override
    public void masterAmountPay(PayResultDTO payResultDTO) throws Exception {

        OmsPayRequestDTO omsPayRequestDTO = JSON.parseObject(payResultDTO.getRequestData(), OmsPayRequestDTO.class);
        Long workId = omsPayRequestDTO.getWorkId();
        Long orderId = omsPayRequestDTO.getOrderId();

        // 1、设置工单为已完成，完成时间，完成标识
        OrderWork orderWork = new OrderWork();
        orderWork.setOrderId(orderId);
        orderWork.setWorkId(workId);
        orderWork.setMasterPayStatus(PayConsts.PAY_STATUS_DONE);
        orderWork.setMasterPayTime(payResultDTO.getPayTime());
        orderWork.setMasterPayChannelId(payResultDTO.getChannelId());
        orderWork.setPayStatus(PayConsts.PAY_STATUS_DONE);
        orderWork.setPayTime(payResultDTO.getPayTime());

        financeWorkService.updateMasterAmountPay(orderWork);

    }

    @Override
    public void depositAmountPay(PayResultDTO payResultDTO) {

    }
}
